package com.dxq.test.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.dxq.test.R;
import com.dxq.test.db.Event;
import com.dxq.test.db.Label;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class LabelAdapter  extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<Label> recordlists = new ArrayList<>(); //预制放行申请列表集合

    public LabelAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void addList(List<Label> temp) {
        if(temp != null){
            recordlists.addAll(temp);
        }
        notifyDataSetChanged();
    }

    public void reAddList(List<Label> temp) {
        recordlists = temp;
        notifyDataSetChanged();
    }

    public void clearList() {
        recordlists.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return recordlists.size();
    }

    @Override
    public Object getItem(int position) {
        return recordlists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Label label = recordlists.get(position);
        ItemHolder itemHolder;
        if(null != convertView) {
            itemHolder =(ItemHolder) convertView.getTag();
        } else {
            LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = li.inflate(R.layout.item_label, parent, false);
            itemHolder = new ItemHolder();
            itemHolder.tvName = (TextView) convertView.findViewById(R.id.tvName); //名称
            itemHolder.tvSex = (TextView) convertView.findViewById(R.id.tvSex); //性别
            itemHolder.tvEvent = (TextView) convertView.findViewById(R.id.tvEvent); //性别
            itemHolder.tvTime = (TextView) convertView.findViewById(R.id.tvTime); //时间时间

            convertView.setTag(itemHolder);
        }
        itemHolder.tvName.setText(label.getName());
        itemHolder.tvSex.setText(label.getSex());
//        Event eventID = label.getEvent_id();
//        if (eventID == null) {
//            itemHolder.tvEvent.setText("未设置事件");
//            itemHolder.tvTime.setText("----");
//        } else {
//            itemHolder.tvEvent.setText(eventID.getName());
//            itemHolder.tvTime.setText(eventID.getTime());
//        }
        return convertView;
    }

    class ItemHolder {
        TextView tvName, tvSex, tvEvent, tvTime;
    }


}
